import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import * as mongoose from 'mongoose';

@Injectable()
export class GoodsTypeAttributeService {
    constructor(@InjectModel('GoodsTypeAttribute') private readonly goodsTypeAttributeModel) {}
    async find(where = {}) {
        return await this.goodsTypeAttributeModel.find().where(where).populate({ path: 'goods_type_id', model: 'GoodsType' });
    }
    async create(goodsTypeAttributeInfo) {
        const cateId = goodsTypeAttributeInfo.cate_id;
        if (cateId) {
            goodsTypeAttributeInfo.cate_id = new mongoose.Types.ObjectId(cateId);
        }
        console.log(goodsTypeAttributeInfo);
        return await this.goodsTypeAttributeModel.create(goodsTypeAttributeInfo);
    }
    async update(goodsTypeAttributeInfo) {
        return await this.goodsTypeAttributeModel.updateOne({ _id: goodsTypeAttributeInfo._id }, goodsTypeAttributeInfo);
    }
    async delete(goodsTypeAttributeInfo) {
        return await this.goodsTypeAttributeModel.deleteOne(goodsTypeAttributeInfo);
    }
    getModel() {
        return this.goodsTypeAttributeModel;
    }
}
